unit untDataTransmit;

interface

uses
  Classes,untHttpConnection;

type
  TDataTransmit = class(TThread)
  private
    { Private declarations }
    FServerIP:String;
    FServerPort:integer;
    FUrl:String;
    FCookieVal:TStringList;
    FMethod:integer;
    FRequestData:String;
    FRecvData:^String;
    tmpStr:String;
  protected
    procedure Execute; override;
    procedure SetRecvData;
  public
    constructor Create(Server:String;Port:integer;Url:String;var CookieVal:TStringList;var RecvData:String;Method:integer = GetMethod;RequestData:String='');
  end;

implementation

uses Unit1;


{ Important: Methods and properties of objects in visual components can only be
  used in a method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure TDataTransmit.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ TDataTransmit }

constructor TDataTransmit.Create(Server: String; Port: integer;
  Url: String; var CookieVal: TStringList;var RecvData:String;
  Method: integer; RequestData: String);
begin
  FServerIP := Server;
  FServerPort := Port;
  FUrl := Url;
  FCookieVal := CookieVal;
  FMethod := Method;
  FRequestData := RequestData;
  FRecvData := @(RecvData);
  inherited Create(False);
end;

procedure TDataTransmit.Execute;
begin
  try
    if FMethod = GetMethod then
    begin
      tmpStr := getHttpDataByGetMethod(FServerIP,FServerPort,FUrl,FCookieVal);
    end
    else if FMethod = PostMethod then
    begin
      tmpStr:=getHttpDataByPostMethod(FServerIP,FServerPort,FUrl,FCookieVal,FRequestData);
    end;
  except
    tmpStr := '';
  end;
  Synchronize(SetRecvData);
end;

procedure TDataTransmit.SetRecvData;
begin
  FRecvData^ := tmpStr;
end;

end.
